<template>
	<view class="shopstore-service" style="padding-top: 1rpx;" :style="{background:pageColor}">

		<view class="ml-md mr-md" :class="[{'flex-warp':service_list_type===3}]">
			<view class="mt-md"
				:class="[{'fill-base pd-lg radius-16':service_list_type!==3 && service_list_type!==4},{'mr-md':service_list_type===3&&index%2==0}]"
				v-for="(item,index) in list.data" :key="index">
				<longbingbing-service-list-item :info="item" :o="{type:service_list_type}"
					:store_id="options.id"></longbingbing-service-list-item>
			</view>
		</view>

		<load-more :noMore="list.current_page >= list.last_page && list.data.length > 0" :loading="loading">
		</load-more>
		<abnor v-if="!loading && list.data.length <= 0 && list.current_page == 1" :isCenter="true"></abnor>

		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import longbingbingServiceListItem from "@/components/longbingbing-service-list-item.vue"
	export default {
		components: {
			longbingbingServiceListItem
		},
		data() {
			return {
				options: {},
				loading: true,
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				count: {}
			}
		},
		computed: mapState({
			service_list_type: state => state.config.configInfo.service_list_type,
		}),
		onLoad(options) {
			this.options = options
			let {
				app_model_type
			} = this
			uni.setNavigationBarTitle({
				title: `预约项目`
			})
			this.$util.setNavigationBarColor({
				bg: this.primaryColor
			})
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.param.page = this.param.page + 1;
			this.loading = true;
			this.getList();
		},
		methods: {
			...mapMutations([]),
			async initIndex(refresh = false) {
				await this.getList()
				// #ifdef H5
				if (!refresh) {
					this.$jweixin.hideOptionMenu()
				}
				// #endif
			},
			async initRefresh() {
				this.param.page = 1
				await this.initIndex(true)
			},
			async getList() {
				let {
					list: oldList,
					param,
				} = this
				let {
					id
				} = this.options
				param.id = id
				let newList = await this.$api.shopstore.storeServiceList(param)
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			}
		}
	}
</script>

<style lang="scss">
</style>